package schoolWork;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: tao
 * Date: 2023-12-10
 * Time: 13:45
 */
public class Work2 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            int count = 0;
            for (int i = 2; i < 10_0000; i++) {
                if(isPrime(i)) {
                    System.out.print(i + " ");
                    count++;
                }
            }
            System.out.println("10w到20w之间的素数：" + count);
        });
        Thread t2 = new Thread(() -> {
            int count = 0;
            for (int i = 10_0000; i < 20_0000; i++) {
                if(isPrime(i)) {
                    System.out.print(i +" ");
                    count++;
                }
            }
            System.out.println();
            System.out.println("10w到20w之间的素数：" + count);
        });
        t1.start();
        t2.start();
    }
    public static boolean isPrime(int num) {
        if(num <= 1) return false;
        for (int i = 2; i <= Math.sqrt(num); i++) {
            if(num % i == 0) return false;
        }
        return true;
    }
}
